// AWTScrollPane.h: interface for the AWTScrollPane class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AWTSCROLLPANE_H__D93AF5B8_A6E0_11D2_A455_006097A44215__INCLUDED_)
#define AFX_AWTSCROLLPANE_H__D93AF5B8_A6E0_11D2_A455_006097A44215__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "AWTContainer.h"

class AWTScrollPane;

class AFX_EXT_CLASS PeerFixer : public AWTObject,
                  public AWTAdjustmentListener
{
public:
	PeerFixer(AWTScrollPane* scroller) 
	{
		m_scroller = scroller;
	}
	virtual ~PeerFixer(){}

	void adjustmentValueChanged(AWTAdjustmentEvent* e);

protected:
	AWTScrollPane* m_scroller;
};

class AFX_EXT_CLASS ScrollPaneAdjustable : public AWTObject,
	                           public AWTAdjustable
{
public:
	ScrollPaneAdjustable(AWTScrollPane* sp, AWTAdjustmentListener* l, int orientation)
	{
		m_minimum = 0;
		m_maximum = 0;
		m_visibleAmount = 0;
		m_unitIncrement = 1;
		m_blockIncrement = 1;
		m_value = 0;
		m_sp = sp;
    m_orientation = orientation;
		addAdjustmentListener(l);
	}
	virtual ~ScrollPaneAdjustable(){}

	void setSpan(int min, int max, int visible);

	virtual int getOrientation() 
		{return m_orientation;}
	virtual void setMinimum(int min){}
	virtual int getMinimum() 
		{return 0;}
	virtual void setMaximum(int max) {}
  virtual int getMaximum() 
		{return m_maximum;}
	virtual void setUnitIncrement(int u);
  virtual int getUnitIncrement() 
		{return m_unitIncrement;}
  virtual void setBlockIncrement(int b) 
		{m_blockIncrement = b;}    
  virtual int getBlockIncrement() 
		{return m_blockIncrement;}
  virtual void setVisibleAmount(int v){}
  virtual int getVisibleAmount() 
		{return m_visibleAmount;}
  virtual void setValue(int v);
  virtual int getValue() 
		{return m_value;}

  virtual void addAdjustmentListener(AWTAdjustmentListener* l) 
		{m_adjustmentListener = AWTEventMulticaster::add(m_adjustmentListener, l);}
  virtual void removeAdjustmentListener(AWTAdjustmentListener* l)
		{m_adjustmentListener = AWTEventMulticaster::remove(m_adjustmentListener, l);}

	virtual AWTAdjustable* getAdjustable()
		{return dynamic_cast<AWTAdjustable*>(this);}

protected:
  AWTScrollPane* m_sp;
  int m_orientation;
  int m_minimum;
  int m_maximum;
  int m_visibleAmount;
  int m_unitIncrement;
  int m_blockIncrement;
  int m_value;
  AWTAdjustmentListener* m_adjustmentListener;
};

class AFX_EXT_CLASS AWTScrollPane : public AWTContainer  
{
DECLARE_DYNAMIC(AWTScrollPane)
public:
	AWTScrollPane();
	AWTScrollPane(int scrollbarDisplayPolicy);
	virtual ~AWTScrollPane();

	enum {
		SCROLLBARS_AS_NEEDED = 0,
		SCROLLBARS_ALWAYS,	
		SCROLLBARS_NEVER
	};

private:
	void construct(int scrollbarDisplayPolicy)
	{
		m_layoutManager = NULL;
		m_w = 100;
		m_h = 100;
		m_scrollbarDisplayPolicy = scrollbarDisplayPolicy;
		m_vAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this), AWTAdjustable::VERTICAL);
		m_hAdjustable = new ScrollPaneAdjustable(this, new PeerFixer(this), AWTAdjustable::HORIZONTAL);
	}

	int getScrollbarDisplayPolicy() 
		{return m_scrollbarDisplayPolicy;}
	CSize getViewportSize();
  int getHScrollbarHeight();
	int getVScrollbarWidth();
	AWTAdjustable* getVAdjustable() 
		{return m_vAdjustable;}
	AWTAdjustable* getHAdjustable() 
		{return m_hAdjustable;}
	void setScrollPosition(int x, int y);
	void setScrollPosition(CPoint p) 
		{setScrollPosition(p.x, p.y);}
	CPoint getScrollPosition();
	virtual void setLayout(AWTLayoutManager* mgr){}
  virtual void doLayout() 
		{layout();}
	CSize calculateChildSize();
	void layout();

	virtual CWnd* createComponent();

protected:
  virtual void addImpl(AWTComponent* comp, CString& constraints, int index);
//	virtual CSize getPreferredSize();
	virtual CSize getMinimumSize()
		{return getPreferredSize();}
	virtual CSize getPreferredSize();

  int m_scrollbarDisplayPolicy;
  ScrollPaneAdjustable* m_vAdjustable;
  ScrollPaneAdjustable* m_hAdjustable;
};

#endif // !defined(AFX_AWTSCROLLPANE_H__D93AF5B8_A6E0_11D2_A455_006097A44215__INCLUDED_)
